/**
 * Created by Administrator on 2017/9/22.
 */
$(function () {
	

	// 购物车没有商品时
	// $("#shoppingcart .note .continue-select").on("click",function () {
	// 	window.location.href="index.html";
	// })
	// $("#shoppingcart .note .closenote").on("click",function () {
	// 	$(this).parent().parent().css("display","none")
	// })
	// 购物车中有商品时
	
	if($.cookie("userInfo")){
		$(".pleaselogin").html($.cookie("userInfo").user).siblings().css("display","none");
		$obj=JSON.parse($.cookie(JSON.parse($.cookie('userInfo')).user));
		for(var i=0;i<$obj.length;i++){
			$("<tr><td><a><img src='"+$obj[i].src +"'></a></td><td><a>"+$obj[i].product_name+"</a></td><td>74</td><td><del>1000</del></td><td>￥418</td><td>1</td><td class='goods-price'>"+$obj[i].price+"</td><td><a class='delete'>删除</a></td></tr>").appendTo("#cartItems-table tbody");
		}
	}else{
		$obj=JSON.parse($.cookie("myShop"));
		for(var i=0;i<$obj.length;i++){
			$("<tr><td><a><img src='"+$obj[i].src +"'></a></td><td><a>"+$obj[i].product_name+"</a></td><td>74</td><td><del>1000</del></td><td>￥418</td><td>1</td><td class='goods-price'>"+$obj[i].price+"</td><td><a class='delete'>删除</a></td></tr>").appendTo("#cartItems-table tbody");
		}
	}
	
	
	
	//删除商品
	$(".cartItems .delete").on("click",function () {
		$(this).parent().parent().remove();
	})
	console.log($(".goods-price").length);
	$total=0;
	for (var i = 0; i < $(".goods-price").length; i++) {
		$total+=parseInt($(".goods-price").text());
		$(".total").text($total);
	}
	
})
